package editor{
	
	import components.MediatorButton;
	import components.ProcessCanvas;
	
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	
	import model.xpdl2.Package;
	
	import mx.containers.Panel;
	import mx.controls.TileList;
	import mx.core.Application;
	
	import util.ConfigUtil;
	import util.HtmlWindow;
	import util.ProcessUtil;
	
	/*
	 * Singleton Class.... 暂时没有考虑同步问题....
	 * FT! 竟然不支持private 构造函数........ 其他地方调用时, 不用new.. 通过createInstance(); 
	 * */
	 
	public class WorkflowexApp{	
		
		private var configPanel:Panel;
		
		private var app:Application;
		
		private var pack:Package;	
		
		private var flow:ProcessCanvas;	
		
		private var icons_common:TileList;
		
		private var icons_task:TileList;
		
		private var icons_start:TileList;
		
		private var icons_end:TileList;
		
		private var icons_inter:TileList;
		
		private var icons_gateway:TileList;
		
		private var drivePanel:Panel;
		
		private var monitorPanel:Panel;
		
		private var driveBtn:MediatorButton;
		
		private var monitorBtn:MediatorButton;
		
		private var config:ConfigUtil;
		
		private var htmlWindow:HtmlWindow;
		
		private static var instance:WorkflowexApp;
		
		public function WorkflowexApp(){
			
		}
		
		public static function createInstance():WorkflowexApp{
			if(instance==null){
				instance=new WorkflowexApp();
			}else{
			
			}
			
			return instance;
		}
		
		
		
		public function testXMLLoader():void{
			
			var loader:URLLoader=new URLLoader();
			loader.dataFormat=URLLoaderDataFormat.TEXT;
			loader.addEventListener(Event.COMPLETE, handleXMLLoaderComplete);
			loader.load(new URLRequest("/test/test.xpdl2"));
			  
        }
          
        public function handleXMLLoaderComplete(event:Event):void{
          	 
          	var xml:XML=new XML(event.target.data);
          	pack=new Package();
          	pack.initPackage(xml);         	
          	
          	trace(config.getProcessURL());
        	ProcessUtil.initCavas(this.pack,this.flow,this, app, drivePanel, monitorPanel, driveBtn, monitorBtn,config);
        	
        }
        
        public function getPackage():Package{
        	
        	return this.pack;
        	
        }
        
        public function setFlow(flow:ProcessCanvas):void{
        
        	this.flow=flow;
        
        }
        
        public function getFlow():ProcessCanvas{
        	
        	return this.flow;
        	
        }
        
        public function setIcons(im:TileList,it:TileList,ist:TileList,ie:TileList,ii:TileList,ig:TileList):void{
        	
        	this.icons_common=im;
        	this.icons_task=it;
        	this.icons_start=ist;
        	this.icons_end=ie;
        	this.icons_inter=ii;
        	this.icons_gateway=ig;
        	
        }
        
        public function getComIcons():TileList{
        	return this.icons_common;
        }
        
        public function getTaskIcons():TileList{
        	return this.icons_task;
        }
        
        public function getStartIcons():TileList{
        	return this.icons_start;
        }
        
        public function getEndIcons():TileList{
        	return this.icons_end;
        }
        
        public function getInterIcons():TileList{
        	return this.icons_inter;
        }
        
        public function getGatewayIcons():TileList{
        	return this.icons_gateway;
        }
           
        public function setApplication(a:Application):void{
        	this.app=a;
        	drivePanel=new Panel();
          	monitorPanel=new Panel();
          	drivePanel.x=0;
          	drivePanel.y=0;
          	drivePanel.width=0;
          	drivePanel.height=0;
          	monitorPanel.x=0;
          	monitorPanel.y=0;
          	monitorPanel.width=0;
          	monitorPanel.height=0;
          	
          	app.addChild(drivePanel);
          	app.addChild(monitorPanel);
        }
        
        public function getApplication():Application{
        	return this.app;
        }
        
        public function setDriveBtn(d:MediatorButton):void{
        	this.driveBtn=d;
        }
        
        public function getDriveBtn():MediatorButton{
        	return this.driveBtn;
        }
        
        public function setMonitorBtn(d:MediatorButton):void{
        	this.monitorBtn=d;
        }
        
        public function getMonitorBtn():MediatorButton{
        	return this.monitorBtn;
        }
        
        public function setConfig(v:ConfigUtil):void{
        	this.config=v;
        }
        
        public function getConfig():ConfigUtil{
        	return this.config;
        }
        
        public function getHtmlWindow():HtmlWindow{
        	return this.htmlWindow;
        }
        
        public function setHtmlWindow(v:HtmlWindow):void{
        	this.htmlWindow=v;
        }
        
        public function setDrivePanel(d:Panel):void{
        	this.drivePanel=d;
        }
        
        public function getDrivePanel():Panel{
        	return this.drivePanel;
        }
        
        public function setMonitorPanel(d:Panel):void{
        	this.monitorPanel=d;
        }
        
        public function getMonitorPanel():Panel{
        	return this.monitorPanel;
        }
        
        public function setConfigPanel(d:Panel):void{
        	this.configPanel=d;
        }
        
        public function getConfigPanel():Panel{
        	return this.configPanel;
        }

		
	}
}